package hydrap2p.library.hashers.common;

import hydrap2p.helper.ServiceConnector;
import hydrap2p.helper.ThriftServerThread;
import hydrap2p.logging.Level;

import org.apache.thrift.TException;


public class RegisterLibrary implements Runnable {
	private String algorithm;
	private ThriftServerThread thread;
	
	public RegisterLibrary(ThriftServerThread thread, String algorithm)
	{
		this.thread=thread;
		this.algorithm=algorithm;
	}
	
	@Override
	public void run()
	{
		// Tell Library about location
		try {
			ServiceConnector.getLibrary().registerHashGenerator(algorithm, thread.getLocation());
			HashLogging.log(Level.INFO, "HashGenerator."+algorithm, "Registered algorithm with Library");
		} catch (TException e) {
			HashLogging.log(Level.FATAL, "HashGenerator."+algorithm, "Failed to tell Library about my location");
			thread.shutdown();
		}
	}
}
